namespace AppManage.EntityFramework.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class basePermission : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Functions",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        FunctionName = c.String(nullable: false, maxLength: 50),
                        ModuleId = c.Int(),
                        FunctionAction = c.String(nullable: false, maxLength: 100),
                        Description = c.String(maxLength: 200),
                        IsActive = c.Boolean(),
                        FunctionDisplayName = c.String(maxLength: 100),
                        Icon = c.String(maxLength: 100),
                        CreatedBy = c.Int(nullable: false),
                        CreatedOn = c.DateTime(),
                        ModifiedBy = c.Int(nullable: false),
                        ModifiedOn = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Modules", t => t.ModuleId)
                .Index(t => t.ModuleId);
            
            CreateTable(
                "dbo.Items",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ItemName = c.String(nullable: false, maxLength: 50),
                        ParentItemId = c.Int(),
                        FunctionId = c.Int(),
                        ControlName = c.String(maxLength: 100),
                        Icon = c.String(maxLength: 100),
                        IsActive = c.Boolean(),
                        Description = c.String(maxLength: 200),
                        CreatedBy = c.Int(nullable: false),
                        CreatedOn = c.DateTime(),
                        ModifiedBy = c.Int(nullable: false),
                        ModifiedOn = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Functions", t => t.FunctionId)
                .Index(t => t.FunctionId);
            
            CreateTable(
                "dbo.Modules",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ModuleName = c.String(nullable: false, maxLength: 50),
                        IsActive = c.Boolean(),
                        Description = c.String(maxLength: 200),
                        CreatedBy = c.Int(nullable: false),
                        CreatedOn = c.DateTime(),
                        ModifiedBy = c.Int(nullable: false),
                        ModifiedOn = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Permissions",
                c => new
                    {
                        PermissionId = c.Int(nullable: false, identity: true),
                        MemberId = c.Int(),
                        MemberTypeId = c.Int(nullable: false),
                        ResourceId = c.Int(),
                        ResourceTypeId = c.Int(nullable: false),
                        AccessTypeId = c.Int(nullable: false),
                        CreatedBy = c.Int(nullable: false),
                        CreatedOn = c.DateTime(),
                        ModifiedBy = c.Int(nullable: false),
                        ModifiedOn = c.DateTime(),
                    })
                .PrimaryKey(t => t.PermissionId);
            
            CreateTable(
                "dbo.Roles",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        RoleName = c.String(nullable: false, maxLength: 50),
                        Description = c.String(maxLength: 200),
                        IsActive = c.Boolean(),
                        CreatedBy = c.Int(nullable: false),
                        CreatedOn = c.DateTime(),
                        ModifiedBy = c.Int(nullable: false),
                        ModifiedOn = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.UserRoles",
                c => new
                    {
                        UserRoleId = c.Int(nullable: false, identity: true),
                        UserId = c.Int(),
                        RoleId = c.Int(),
                        CreatedBy = c.Int(nullable: false),
                        CreatedOn = c.DateTime(),
                    })
                .PrimaryKey(t => t.UserRoleId)
                .ForeignKey("dbo.Roles", t => t.RoleId)
                .ForeignKey("dbo.Users", t => t.UserId)
                .Index(t => t.RoleId)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserName = c.String(maxLength: 50),
                        Password = c.String(maxLength: 50),
                        Email = c.String(maxLength: 100),
                        IsActive = c.Boolean(),
                        CreatedBy = c.Int(nullable: false),
                        CreatedOn = c.DateTime(),
                        ModifiedBy = c.Int(nullable: false),
                        ModifiedOn = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.UserRoles", "UserId", "dbo.Users");
            DropForeignKey("dbo.UserRoles", "RoleId", "dbo.Roles");
            DropForeignKey("dbo.Functions", "ModuleId", "dbo.Modules");
            DropForeignKey("dbo.Items", "FunctionId", "dbo.Functions");
            DropIndex("dbo.UserRoles", new[] { "UserId" });
            DropIndex("dbo.UserRoles", new[] { "RoleId" });
            DropIndex("dbo.Functions", new[] { "ModuleId" });
            DropIndex("dbo.Items", new[] { "FunctionId" });
            DropTable("dbo.Users");
            DropTable("dbo.UserRoles");
            DropTable("dbo.Roles");
            DropTable("dbo.Permissions");
            DropTable("dbo.Modules");
            DropTable("dbo.Items");
            DropTable("dbo.Functions");
        }
    }
}
